<?php
class controller_admin_community_review extends system_user_controller_panel {	

	private $concept = null;
	public function init() {
		if(!parent::init()) {
			return ;
		}
		$this->concept = new community_review_concept($this->user->getLang());
		$this->_crumbs()->addPage(system_nav_page::create($this->language('Community'))->setRoute('community/index'));
		$this->_crumbs()->addPage(system_nav_page::create($this->language('Review'))->setRoute('community/review/index'));
	}

	public function action_index() {
		$this->_goRoute('community/review/list');
		$this->render();
	}
	
	public function action_list() {
		$this->_batchDelete($this->concept, 'id', 'id');	
		$adapter = new system_paginator_adapter_concept($this->concept);
		$adapter->setCurrentPageNumber(intval($this->_param('page', 1)));
	
		$this->view->order = $order = strtolower($this->_get('order'));
		$keyword = trim($this->_get('keyword'));
		if($keyword == self::$_keyword) $keyword = '';
		if($keyword) {
			$adapter->where("`message` LIKE ? OR `ip` LIKE ?", "%$keyword%");
		}
		$this->view->category = $category = intval($this->_get('category'));
		if($category) {
			$adapter->where("`category` = ?", $category);
		}
	
		$_order = array('id DESC');
		if($order) {
			$this->view->sort = $sort = intval($this->_get('sort'));
			$_sort = !$sort ? 'DESC' : 'ASC';
			if($order == 'date') {
				$order = 'creationtime';
			}
			$_order = array("$order $_sort");
		}
		$adapter->setLimit(30);
		$adapter->order($_order);
		$this->view->list = new system_paginator($adapter);
		$this->_crumbs()->addPage(system_nav_page::create($this->language('List'))->setRoute('community/review/list'));
		$this->render();
	}
	
}
